package cn.common.mybatis;

public class OracleTranslator extends DefaultTranslator {

	@Override
	public String batchBegin() 
	{
		return "begin";
	}

	@Override
	public String batchEnd()
	{
		return "end;";
	}

	
	@Override
	public String sysdate() 
	{
		return "sysdate";
	}

	@Override
	public String nextvalSql(String seqName) 
	{
		return "SELECT "+seqName+".NEXTVAL FROM DUAL";
	}

	@Override
	public String nextval(String seqName) 
	{
		return seqName+".NEXTVAL";
	}

	@Override
	public String concat(String... str) 
	{
		StringBuilder sb=new StringBuilder();
		for(String s:str)
			sb.append("||").append(s);
		return sb.substring(2);
	}

	@Override
	public String nextvalN(String seqName, String n) 
	{
		return "SELECT "+seqName+".NEXTVAL FROM DUAL CONNECT BY LEVEL<="+n;
	}

	@Override
	public String limit(String count, boolean hasCriteria) 
	{
		return (hasCriteria?"AND":"")+" ROWNUM<"+count;
	}

	@Override
	public String strToDate(String dateStr, String format) 
	{
		if(format==null)
			return "";
		if("yyyy-MM-dd HH:mm:ss".equals(format))
			return "to_date("+dateStr+",'yyyy-MM-dd HH24:mi:ss')";
		else if("yyyy-MM-dd".equals(format))
			return "to_date("+dateStr+",'yyyy-MM-dd')";
		return "to_date("+dateStr+",'"+format+"')";
	}

	@Override
	public String keywordEscape(String keyword) 
	{
		return "\""+keyword+"\"";
	}

}
